﻿using System;
using System.Collections.Generic;
using System.Text;
using Common.Utilities;

namespace Workflows.Components.TextMining.Collapse
{
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public class EvaluableFieldAttribute:Attribute
    {
        #region fields
        private FieldType _FieldType;
        private ValueEvaluateMethods _EvaluateMethod;
        private string _FieldName;
        private double _Weight;
        private double _FromValue;
        private double _ToValue;
        private int _MinLen;
        private int _MaxLen;
        private bool _AllowNull;
        private IFieldEvaluator _Evaluator;
        #endregion

        public EvaluableFieldAttribute(string fieldName,FieldType fieldType)
        {
            this.FieldName = fieldName;
            this.FieldType = fieldType;
            this._EvaluateMethod = ValueEvaluateMethods.Equals;
            this._Weight = 1;
            this._FromValue = double.MinValue;
            this._ToValue = double.MaxValue;
            this._MinLen = 0;
            this._MaxLen = int.MaxValue;
            this.AllowNull = false;
            switch(this._FieldType)
            {
                case FieldType.Category:
                    this._Evaluator = new CategoryEvaluator();
                    break;
                case FieldType.Character:
                    this._Evaluator = new StringEvaluator();
                    break;
                case FieldType.DateTime:
                    this._Evaluator = new DateTimeEvaluator();
                    break;
                case FieldType.Number:
                    this._Evaluator = new NumberEvaluator();
                    break;
                case FieldType.TrueFalse:
                    this._Evaluator = new BooleanEvaluator();
                    break;
                default:
                    this._Evaluator = new StringEvaluator();
                    break;
            }
        }

        public EvaluableFieldAttribute(string fieldName, FieldType fieldType, ValueEvaluateMethods evalMethod)
            :this(fieldName,fieldType)
        {
            this._EvaluateMethod = evalMethod;
        }

        #region props
        public FieldType FieldType
        {
            get { return _FieldType; }
            set { _FieldType = value; }
        }

        public ValueEvaluateMethods EvaluateMethod
        {
            get { return _EvaluateMethod; }
            set { _EvaluateMethod = value; }
        }

        public string FieldName
        {
            get { return _FieldName; }
            set { _FieldName = value; }
        }

        public double Weight
        {
            get { return _Weight; }
            set { _Weight = value; }
        }

        public double FromValue
        {
            get { return _FromValue; }
            set { _FromValue = value; }
        }

        public double ToValue
        {
            get { return _ToValue; }
            set { _ToValue = value; }
        }

        public int MinLen
        {
            get { return _MinLen; }
            set { _MinLen = value; }
        }

        public int MaxLen
        {
            get { return _MaxLen; }
            set { _MaxLen = value; }
        }

        public bool AllowNull
        {
            get { return _AllowNull; }
            set { _AllowNull = value; }
        }

        public IFieldEvaluator Evaluator
        {
            get { return _Evaluator; }
            set { _Evaluator = value; }
        }

        #endregion
    }
}
